package com.iwdm.renovation.ui.designer;

import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.iwdm.renovation.ChatActivity;
import com.iwdm.renovation.R;
import com.iwdm.renovation.databinding.FragmentDesignerItemBinding;
import com.iwdm.renovation.ui.designer.details.DesignerActivity;

import java.util.Random;


public class MyDesignerRecyclerViewAdapter extends RecyclerView.Adapter<MyDesignerRecyclerViewAdapter.ViewHolder> {

    private FragmentDesignerItemBinding binding;

    public MyDesignerRecyclerViewAdapter() {
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        binding = FragmentDesignerItemBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false);
        return new ViewHolder(binding);
    }

    @Override
    public void onBindViewHolder(final ViewHolder holder, int position) {
        Random random = new Random();
        holder.imageView.setImageResource(random.nextBoolean() ? R.drawable.img6 : R.drawable.img2);
        holder.title.setText(random.nextBoolean() ? "吾索设计" : "索吾全屋设计");
        holder.btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                v.getContext().startActivity(new Intent(v.getContext(), ChatActivity.class));
            }
        });
        holder.mView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                v.getContext().startActivity(new Intent(v.getContext(), DesignerActivity.class));
            }
        });
    }

    @Override
    public int getItemCount() {
        return 30;
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        public final View mView;
        public final TextView title;
        public ImageView imageView;
        public Button btn;

        public ViewHolder(FragmentDesignerItemBinding binding) {
            super(binding.getRoot());
            mView = binding.getRoot();
            title = binding.title;
            imageView = binding.img;
            btn = binding.btn;
        }
    }
}
